<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./node_modules/vue/dist/vue.js"></script>

</head>
<body>
    <div id="root">
        <counter ref="one" @change="handleChange"></counter>
        <counter ref="two" @change="handleChange"></counter>
        <div>{{total}}</div>
    </div>
    

    <script>
        Vue.component(
            'counter',
            {
                template:"<div @click='handleClick'>{{number}}</div>",
                data(){
                    return{
                        number:0
                    }
                },
                    methods:{
                        handleClick:function(){
                            this.number++
                            this.$emit('change')
                        }
                    }
                }
            
        )


        var vm = new Vue({
            el:"#root",
            data:{
                total:0
            },
            methods:{
                handleChange(){
                    // 求子组建两个数据的和就要用到ref
                   this.total= this.$refs.one.number+this.$refs.two.number
                }
            }
        })
    </script>

</body>
</html>